import {http} from '../../http'
import {GetMyAddressListParam, GetOneAddressInfoParam, UserAddressParam} from './param'
import {ResponsePage} from '../../type'
import {UserAddressDto} from './response'

//获取我的地址列表
const getMyAddressList = (params: GetMyAddressListParam) => http.get<GetMyAddressListParam, ResponsePage<UserAddressDto>>('/user/address', params)

//添加地址
const addUserAddress = (params: UserAddressParam) => http.post<UserAddressParam, number>('/user/address', params)

//修改地址信息
const updateUserAddress = (params: UserAddressParam) => http.put<UserAddressParam, void>('/user/address', params)

//获取默认地址
const getDefaultUserAddress = () => http.get<void, UserAddressDto>('/user/address/default')

//获取一个地址信息
const getOneAddressInfo = (params: GetOneAddressInfoParam) => http.get<void, UserAddressDto>(`/user/address/${params.addressId}`)

//删除地址信息
const deleteOneAddress = (params: GetOneAddressInfoParam) => http.delete<void, void>(`/user/address/${params.addressId}`)

//设置默认地址信息
const setDefaultAddress = (params: GetOneAddressInfoParam) => http.put<void, void>(`/user/address/${params.addressId}/default`)

export default {
  getMyAddressList,
  addUserAddress,
  updateUserAddress,
  getDefaultUserAddress,
  getOneAddressInfo,
  deleteOneAddress,
  setDefaultAddress
}